package main

import (
	"encoding/json"
	"github.com/gorilla/websocket"
	"net/http"

	"github.com/zeromicro/go-zero/core/logx"
)

func HandleWebSocketError(conn *websocket.Conn, message string, code int) {
	logx.Errorf("WebSocket错误: %s (代码: %d)", message, code)
	conn.WriteMessage(websocket.CloseMessage, websocket.FormatCloseMessage(code, message))
	conn.Close()
}

func HandleAPIError(w http.ResponseWriter, message string, statusCode int) {
	logx.Errorf("API错误: %s (状态码: %d)", message, statusCode)
	w.WriteHeader(statusCode)
	json.NewEncoder(w).Encode(map[string]string{"error": message})
}
